//package com.yc;
//
//import dev.langchain4j.data.image.Image;
//import dev.langchain4j.model.image.ImageModel;
//import dev.langchain4j.model.output.Response;
//import okhttp3.MediaType;
//import okhttp3.OkHttpClient;
//import okhttp3.Request;
//import okhttp3.RequestBody;
//
//import javax.print.attribute.standard.Media;
//import javax.xml.transform.Result;
//
//public class _04_MyImageModelTest{
//    public static void main(String[] args) {
//        ImagedModl imageModl = new ImagedModl(System.getenv("SILICON_API_KEY"));
//        Response<Image> response = imageModl.generate("请生成一个中国的城市地图");
//        System.out.println(response);
//    }
//}
//
//
//class SiliconFlowImageModel implements ImageModel{
//    private final String apiKey;
//    private final OkHttpClient client=new OkHttpClient();
//
//    SiliconFlowImageModel(String apiKey) {
//        this.apiKey = apiKey;
//    }
//
//    @Override
//    public Response<Image> generate(String s) {
//        MediaType mediaType = MediaType.parse("application/json");
//        String json=String.format("{\"prompt\":\"%s\",\"size\":\"1024x1024\",\"n\":1}",s);
//
//        Request request = new Request.Builder()
//                .url("https://api.siliconapi.io/v1/images/generations")
//                .post(RequestBody.create(mediaType,json))
//                .addHeader("Authorization","Bearer"+apiKey)
//               .build();
//
//        try(okhttp3.Response response=client.newCall(request).execute()){
//            if(!response.isSuccessful()) {
//                throw new RuntimeException("Failed to generate image:" + response);
//            }
//            String responseBody=response.body().string();
//
//        int start=responseBody.indexOf("data");
//        int end=responseBody.indexOf("\"",start);
//        String url=responseBody.substring(start,end);
//
//        Image image=Image.builder().url(url).build();
//        Response<Image> result=Response.from(image);
//        return result;
//        }catch(Exception e){
//            e.printStackTrace();
//            throw new RuntimeException("Failed to generate image",e);
//        }
//    }
//}
